﻿Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient

Public Class ExperienciaDB
    Public Shared Function GetCargosExperiencias() As DataSet
        Dim cmd As New SqlCommand("spGetCargosExperiencias", DB.Conexion)
        Dim da As New SqlDataAdapter
        Dim ds As New DataSet

        cmd.CommandType = CommandType.StoredProcedure
        da.SelectCommand = cmd
        da.Fill(ds, "Experiencias")
        Return ds
    End Function

    Public Shared Function InsertarExperiencia(ByVal experiencia As String) As Integer
        Dim cmd As New SqlCommand("spInsertExperiencia", DB.Conexion)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.AddWithValue("@experiencia", experiencia)
        cmd.Parameters.Add("@Error", SqlDbType.Int).Direction = ParameterDirection.Output
        cmd.Parameters.Add("@ErrorDesc", SqlDbType.VarChar, 200).Direction = ParameterDirection.Output
        cmd.Parameters.Add("@id_experiencia", SqlDbType.Int).Direction = ParameterDirection.Output
        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()
        If cmd.Parameters("@error").Value <> 0 Then
            Throw New ApplicationException(cmd.Parameters("@ErrorDesc").Value.ToString())
        End If
        Return cmd.Parameters("@id_experiencia").Value
    End Function

    Public Shared Sub DeleteExperienciaCV(ByVal id_cv As Integer, ByVal id_detalle As Integer)
        Dim cmd As New SqlCommand("spDeleteExperienciaCV", DB.Conexion)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.AddWithValue("@id_cv", id_cv)
        cmd.Parameters.AddWithValue("@id_detalle", id_detalle)
        cmd.Parameters.Add("@Error", SqlDbType.Int).Direction = ParameterDirection.Output
        cmd.Parameters.Add("@ErrorDesc", SqlDbType.VarChar, 200).Direction = ParameterDirection.Output
        cmd.Connection.Open()
        cmd.ExecuteNonQuery()
        cmd.Connection.Close()
        If cmd.Parameters("@error").Value <> 0 Then
            Throw New ApplicationException(cmd.Parameters("@ErrorDesc").Value.ToString())
        End If

    End Sub

   
End Class
